package models

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

type SysLogAdminLogin struct {
	Id        int64      `orm:"column(id);unique;auto;" json:"id"`
	UserName  string     `orm:"column(user_name);description(用户账号)" json:"userName"`
	Ipaddr    string     `orm:"column(ipaddr);description(登录IP地址)" json:"ipaddr"`
	Browser   string     `orm:"column(browser);description(浏览器类型)" json:"browser"`
	Os        string     `orm:"column(os);description(操作系统)" json:"os"`
	Status    int        `orm:"column(status);description(登录状态（1成功 0失败）)" json:"status"`
	Msg       string     `orm:"column(msg);description(提示消息)" json:"msg"`
	LoginTime *time.Time `orm:"column(login_time);description(访问时间)" json:"loginTime"`
}

func init() {
	orm.RegisterModel(new(SysLogAdminLogin))
}

// SearchField 定义模型的可搜索字段
func (*SysLogAdminLogin) SearchField() []string {
	return []string{"status"}
}

// WhereField 定义模型可作为条件的字段
func (*SysLogAdminLogin) WhereField() []string {
	return []string{"id", "status"}
}

// SimpleField 简略查询字段
func (*SysLogAdminLogin) SimpleField() []string {
	return []string{"id"}
}

func (m *SysLogAdminLogin) TableName() string {
	return "sys_log_admin_login"
}

// AddSysLogAdminLogin insert a new SysLogAdminLogin into database and returns
// last inserted Id on success.
func AddSysLogAdminLogin(m *SysLogAdminLogin) (id int64, err error) {
	o := orm.NewOrm()
	id, err = o.Insert(m)
	return
}

// GetSysLogAdminLoginById retrieves SysLogAdminLogin by Id. Returns error if
// Id doesn't exist
func GetSysLogAdminLoginById(id int64) (v *SysLogAdminLogin, err error) {
	o := orm.NewOrm()
	v = &SysLogAdminLogin{}
	if err = o.QueryTable(new(SysLogAdminLogin)).Filter("id", id).RelatedSel().One(v); err == nil {
		return v, nil
	}
	return nil, err
}
